local extension = Package:new("YS__liyue")
extension.extensionName = "2333333"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
     ["YS__liyue"] = "○神-璃月",
     ["YS"] = "○神",
}

---@param player ServerPlayer @ 发起整肃的玩家
---@param target ServerPlayer @ 执行整肃的玩家
---@param skillName string @ 技能名
---@param prompt string @ 提示信息
--发起整肃
local function StartZhengsu(player, target, skillName, prompt)
  skillName = skillName or ""
  prompt = prompt or ""
  local room = player.room
  local choices = {"zhengsu_leijin", "zhengsu_bianzhen", "zhengsu_mingzhi"}
  local choice = room:askForChoice(player, choices, skillName, prompt, true)
  local mark = target:getMark("@" .. choice .. "-turn")
  if mark == 0 then mark = {} end
  table.insertIfNeed(mark, skillName)
  room:setPlayerMark(target, "@" .. choice .. "-turn", mark)
  mark = target:getMark(choice .. "-turn")
  if mark == 0 then mark = {} end
  table.insertIfNeed(mark, player.id)
  room:setPlayerMark(target, choice .. "-turn", mark)
end

---@param room Room @ 房间
---@return integer[]
local function GetRenPile(room)
  room.tag["ren"] = room.tag["ren"] or {}
  return table.simpleClone(room.tag["ren"])
end

local function NotifyRenPile(room)
  room:sendLog{
    type = "#NotifyRenPile",
    arg = #GetRenPile(room),
    card = GetRenPile(room),
  }
  room:setBanner("@$RenPile", table.simpleClone(room.tag["ren"]))
  --room:doBroadcastNotify("ShowToast", Fk:translate("RenPileToast")..table.concat(table.map(GetRenPile(room), function(id) return Fk:getCardById(id):toLogString() end), "、"))
end

---@param room Room @ 房间
---@param card integer|integer[]|Card|Card[] @ 要加入仁区的牌/id/intList
---@param skillName string @ 移动的技能名
---@param proposer integer @ 移动操作者的id
local function AddToRenPile(room, card, skillName, proposer)
  local ids = Card:getIdList(card)
  room.tag["ren"] = room.tag["ren"] or {}
  local ren_cards = table.simpleClone(room.tag["ren"])
  if #ids + #ren_cards <= 6 then
    table.insertTable(room.tag["ren"], ids)
  else
    local rens = {}
    if #ids >= 6 then
      for i = 1, 6, 1 do
        table.insert(rens, ids[i])
      end
    else
      local n = #ids + #ren_cards - 6
      for i = n + 1, #ren_cards, 1 do
        table.insert(rens, ren_cards[i])
      end
      table.insertTable(rens, ids)
    end
    room.tag["ren"] = rens
  end
  local dummy = Fk:cloneCard("dilu")
  dummy:addSubcards(table.filter(ids, function(id) return table.contains(room.tag["ren"], id) end))
  room:moveCardTo(dummy, Card.Void, nil, fk.ReasonJustMove, skillName, nil, true, proposer)
  room:sendLog{
    type = "#AddToRenPile",
    arg = #dummy.subcards,
    card = dummy.subcards,
  }

  local dummy2 = Fk:cloneCard("dilu")
  dummy2:addSubcards(table.filter(ren_cards, function(id) return not table.contains(room.tag["ren"], id) end))
  if #dummy2.subcards > 0 then
    room:moveCardTo(dummy2, Card.DiscardPile, nil, fk.ReasonJustMove, "ren_overflow", nil, true, nil)
    room:sendLog{
      type = "#OverflowFromRenPile",
      arg = #dummy2.subcards,
      card = dummy2.subcards,
    }
  end

  NotifyRenPile(room)
end

---@param room Room @ 房间
---@param player ServerPlayer @ 获得牌的角色
---@param cid integer|Card @ 要获得的牌/id
---@param skillName string @ 技能名
local function GetCardFromRenPile(room, player, cid, skillName)
  skillName = skillName or ""
  if type(cid) ~= "number" then
    cid = cid:isVirtual() and cid.subcards or {cid.id}
  else
    cid = {cid}
  end
  if #cid == 0 then return end
  local move = {
    ids = cid,
    to = player.id,
    toArea = Card.PlayerHand,
    moveReason = fk.ReasonJustMove,
    proposer = player.id,
    moveVisible = true,
    skillName = skillName,
  }
  room.logic:trigger("fk.BeforeRenMove", nil, move)
  room:moveCards(move)
  room.logic:trigger("fk.AfterRenMove", nil, move)
  for _, id in ipairs(cid) do
    table.removeOne(room.tag["ren"], id)
  end
  room:sendLog{
    type = "#GetCardFromRenPile",
    from = player.id,
    arg = #cid,
    card = cid,
  }
  NotifyRenPile(room)
end

---@param room Room @ 房间
---@param player ServerPlayer @ 弃置牌的角色
---@param ids integer|integer[] @ 要弃置的id/idList
---@param skillName string @ 技能名
local function DiscardCardFromRenPile(room, player, ids, skillName)
  skillName = skillName or ""
  if type(ids) ~= "number" then
    ids = ids
  else
    ids = {ids}
  end
  if #ids == 0 then return end
  local move = {
    ids = ids,
    toArea = Card.DiscardPile,
    moveReason = fk.ReasonDiscard,
    proposer = player.id,
    moveVisible = true,
    skillName = skillName,
  }
  room.logic:trigger("fk.BeforeRenMove", nil, move)
  room:moveCards(move)
  room.logic:trigger("fk.AfterRenMove", nil, move)
  for _, id in ipairs(ids) do
    table.removeOne(room.tag["ren"], id)
  end
  room:sendLog{
    type = "#DiscardCardFromRenPile",
    from = player.id,
    arg = #ids,
    card = ids,
  }
  NotifyRenPile(room)
end

Fk:loadTranslationTable{
  ["#NotifyRenPile"] = "“仁”区现有 %arg 张牌 %card",
  ["RenPileToast"] = "仁区：",
  ["#AddToRenPile"] = "%arg 张牌被移入“仁”区 %card",
  ["#OverflowFromRenPile"] = "%arg 张牌从“仁”区溢出 %card",
  ["#GetCardFromRenPile"] = "%from 从“仁”区获得 %arg 张牌 %card",
  ["#DiscardCardFromRenPile"] = "%from 弃置了“仁”区 %arg 张牌 %card",
  ["$RenPile"] = "仁区",
  ["@$RenPile"] = "仁区",
}

local REACTION = General(extension, "REACTION", "Normal", 0, 0)
REACTION.hidden=true
local reaction_rule = fk.CreateTriggerSkill{
  name = "reaction_rule",
}
REACTION:addSkill(reaction_rule)

Fk:loadTranslationTable{
  ["REACTION"] = "元素反应",
  ["reaction_rule"] = "元素反应",
  [":reaction_rule"] = "场上有角色受到属性伤害时，若其没有对应附着，则产生对应属性附着。如果此时满足条件，则会清除对应附着触发元素反应。<br>"..
  "<b>属性伤害</b>：<font color='#00DB00'>草</font>、<font color='#66B3FF'>水</font>、<font color='#EAC100'>岩</font>、<font color='#02F78E'>风</font>，除了<font color='#66B3FF'>水</font>属性伤害，其他属性伤害都不能被铁索传导。<br>"..
  "<font color='#02F78E'>风</font>、<font color='#EAC100'>岩</font>属性只在能产生反应时产生附着<br>"..
  "<b>裂伤</b>：虚拟伤害的一种，造成裂伤时令目标产生一层“裂痕”，拥有两层时移除所有“裂痕”并流失一点体力（至多流失至0）；回复体力时移除所有“裂痕”；属性裂伤可以传导并产生附着<br>"..
  "<b>元素反应</b>：<br>"..
  "<font color='red'>火</font><font color='#95CACA'>冰</font><font color='#66B3FF'>水</font><font color='#8600FF'>雷</font> x <font color='#02F78E'>风</font> = <b>扩散</b>【造成一点裂伤，令该角色相邻角色产生其同类型附着】<br><br>"..
  "<font color='red'>火</font><font color='#95CACA'>冰</font><font color='#66B3FF'>水</font><font color='#8600FF'>雷</font> x <font color='#EAC100'>岩</font>= <b>结晶</b>【获得一点护甲】<br><br>"..
  "<font color='#66B3FF'>水</font> x <font color='red'>火</font> = <b>蒸发</b>【令此次造成伤害+1】<br>"..
  "<font color='grey'>#\"<b>对非玩家单位</b>\"：造成的伤害翻倍。</font><br><br>"..
  "<font color='#95CACA'>冰</font> x <font color='red'>火</font> = <b>融化</b>【令此次造成伤害+1】<br>"..
  "<font color='grey'>#\"<b>对非玩家单位</b>\"：造成的伤害翻倍。</font><br><br>"..
  "<font color='#66B3FF'>水</font> x <font color='#95CACA'>冰</font> = <b>冻结</b>【该角色无法使用或打出牌且所有技能失效直到当前回合结束，且受到<font color='red'>火焰</font>/<font color='grey'>普通</font>伤害时伤害+1并解除冻结（<font color='grey'>碎冰反应</font>）】<br>"..
  "<font color='grey'>#\"<b>对非玩家单位</b>\"：冻结效果持续至其回合结束，且受伤翻倍。</font><br><br>"..
  "<font color='#8600FF'>雷</font> x <font color='red'>火</font> = <b>超载</b>【该角色与其下家交换位置（不能有当前回合角色参与），否则令此次造成伤害+1】<br>"..
  "<font color='grey'>#\"<b>对非玩家单位</b>\"：若其正面向上，翻面；否则，造成的伤害+1。</font><br><br>"..
  "<font color='#66B3FF'>水</font> x <font color='#8600FF'>雷</font> = <b>感电</b>【对该角色和相邻非当前回合角色造成一点裂伤】<br><br>"..
  "<font color='#95CACA'>冰</font> x <font color='#8600FF'>雷</font> = <b>超导</b>【对该角色和相邻非当前回合角色造成一点裂伤】<br><br>"..
  "<font color='#00DB00'>草</font> x <font color='red'>火</font> = <b>燃烧</b>【该角色获得两层<font color='red'>燃烧</font>；<font color='red'>燃烧</font>：每个角色的回合结束时，减少一层<font color='red'>燃烧</font>随机弃置一张牌并产生<font color='red'>火</font>附着（优先弃置装备区）】<br><br>"..
  "<font color='#00DB00'>草</font> x <font color='#8600FF'>雷</font> = <b>激化</b>【摸一张牌并生成两层<font color='#00DB00'>激化</font><font color='#8600FF'>领域</font>；<font color='#00DB00'>激化</font><font color='#8600FF'>领域</font>：造成<font color='#8600FF'>雷</font>/<font color='#00DB00'>草</font>伤害时，移除一层<font color='#00DB00'>激化</font><font color='#8600FF'>领域</font>并摸一张牌】<br><br>"..
  "<font color='#00DB00'>草</font> x <font color='#66B3FF'>水</font> = <b>绽放</b>【该角色获得一层<font color='#00DB00'>草原核</font>；<font color='#00DB00'>草原核</font>：弃牌阶段开始时，移除所有<font color='#00DB00'>草原核</font>减少等量手牌上限并产生<font color='#00DB00'>草</font>附着；受到<font color='red'>火</font>/<font color='#8600FF'>雷</font>属性伤害时，移除所有<font color='#00DB00'>草原核</font>造成等量草伤害】<br>",
}

local YS__zl = General(extension, "YS__zl", "Geo", 4, 4, General.Male)
local YS__zlwin = fk.CreateActiveSkill{ name = "YS__zl_win_audio" }
YS__zlwin.package = extension
Fk:addSkill(YS__zlwin)
local YS__dixing = fk.CreateTriggerSkill{
  name = "YS__dixing",
  anim_type = "special",
  events = {fk.EventPhaseEnd},
  expand_pile = "ji",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Play or
      (player.phase == Player.Finish and #player:getPile("ji") > 0 ))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Play then
      local cards = room:askForCard(player, 1, 999, true, self.name, true, ".", "是否将任意牌置于武将牌上")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    elseif player.phase == Player.Finish then
      local n = 0
      local black = #table.filter(player:getCardIds(Player.Special,"ji"), function(cid)
        return Fk:getCardById(cid).color == Card.Black end)
      local red = #table.filter(player:getCardIds(Player.Special,"ji"), function(cid)
        return Fk:getCardById(cid).color == Card.Red end)
      if #player:getPile("ji") > 3 then
        n = n + 1
      end
      if black > 1 or red > 1 then
        n = n + 1
      end
      if n == 2 then
       local targets = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), function(p)
         return p.id end), 1, 1, "是否发动地心", self.name, true)
       if #targets > 0 then
        self.cost_data = targets
       return true
       end
      else
       return true
     end
    end
  end,
  on_use = function(self, event, target, player, data)
    if player.phase == Player.Play then
      player:broadcastSkillInvoke("YS__dixing", math.random(1,3))
      local dummy = Fk:cloneCard("dilu")
      dummy:addSubcards(self.cost_data)
      player:addToPile("ji", self.cost_data, true, self.name)
    elseif player.phase == Player.Finish then
      local n = 0
      player:broadcastSkillInvoke("YS__dixing", math.random(4,6))
      local room = player.room
      local black = #table.filter(player:getCardIds(Player.Special,"ji"), function(cid)
        return Fk:getCardById(cid).color == Card.Black end)
      local red = #table.filter(player:getCardIds(Player.Special,"ji"), function(cid)
        return Fk:getCardById(cid).color == Card.Red end)
      if #player:getPile("ji") > 3 then
        room:changeShield(player, 1)
        n = n + 1
      end
      if black > 1 or red > 1 then
        room:changeShield(player, 1)
        n = n + 1
      end
      if n == 2 then
      table.forEach(self.cost_data, function(id)
        room:damage{
          from = player,
          to = room:getPlayerById(id),
          damage = 1,
          damageType = 330,
          skillName = self.name,
        }
      end)
    end
      if n ~= 0 then
        room:moveCards({
          from = player.id,
          ids = player:getCardIds(Player.Special,"ji"),
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonPutIntoDiscardPile,
          skillName = self.name,
          specialName = "ji",
        })
      end
    end
  end,
}
local YS__dixingShield = fk.CreateTriggerSkill{
  name = "#YS__dixingShield",
  anim_type = "defence",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
      if player:distanceTo(target)==1 and player:hasSkill(self) and player.shield ~= 0 and data.from ~= player then
          return true
      else
          return false
      end
  end,
  on_use = function(self, event, target, player, data)
      player.room:damage{
          from = data.from,
          to = player,
          damage = data.damage,
          damageType = data.damageType,
          skillName = data.skillName,
          chain = data.chain,
          card = data.card,
      }
      return true
  end,
}
local YS__zhuanyv = fk.CreateTriggerSkill{
  name = "YS__zhuanyv",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.shield ~= 0
  end,
  on_use = function(self, event, target, player, data)
     local room = player.room
     if player.shield ~= 0 then
      if event == fk.DamageInflicted then
        player:drawCards(1)
      elseif event == fk.DrawNCards then
        data.n = data.n + 1
      end
     end
  end,
}
local YS__dangmo = fk.CreateTriggerSkill{
  name = "YS__dangmo",
  frequency = Skill.Wake,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return #player.room.alive_players <= 3
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "YS__A_tianxing", nil)
  end,
}
local YS__A_tianxing = fk.CreateActiveSkill{
  name = "YS__A_tianxing",
  anim_type = "offensive",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.shield ~= 0
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 1 then
    return false
    else
    return true
  end
end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local num = player.shield
    room:changeShield(player, -player.shield)
    room:damage{
      from = player,
      to = to,
      damage = num,
      damageType = 330,
      skillName = self.name,
    }
    to:turnOver()
  end,
}
YS__zl:addSkill(YS__dixing)
YS__dixing:addRelatedSkill(YS__dixingShield)
YS__zl:addSkill(YS__zhuanyv)
YS__zl:addSkill(YS__dangmo)
YS__zl:addRelatedSkill(YS__A_tianxing)
Fk:loadTranslationTable{
  ["YS__zl"] = "钟离",
  ["ji"] = "<font color='#EAC100'>脊</font>",
  ["YS__dixing"] = "地心",
  ["#YS__dixingShield"] = "地心",
  ["YS__zhuanyv"] = "馔玉",
  ["YS__dangmo"] = "荡魔",
  ["YS__A_tianxing"] = "天星",
  [":YS__dixing"] = "锁定技，出牌阶段结束时，你可以将任意张牌置于武将牌上称为“脊”；" ..
  "结束阶段，若“脊”：<br/>"..
  "①有至少两张同色牌，你获得一点护甲；<br/>" ..
  "②不小于四张，你获得一点护甲。<br/>若两项都满足，你可以对一名其他角色造成一点岩元素伤害；若你以此法获得了护甲，则你弃置所有的“脊”。"..
  "<br/>/ / 当一名你与其距离不大于1的其他角色受到来源不为你的伤害时，若你有护甲，则你可以将此伤害转移给你。",
  [":YS__zhuanyv"] = "锁定技，若你有护甲：当你受到伤害时，你摸一张牌；摸牌阶段，你额外摸一张牌。",
  [":YS__A_tianxing"] = "限定技，出牌阶段，若你有护甲，你可以选择一名其他角色失去所有护甲并对其造成等量岩元素伤害，如此做，其翻面。",
  [":YS__dangmo"] = "觉醒技，准备阶段，若场上存活角色不大于3；你获得〖天星〗",
  ["$YS__dixing1"] = "壁立千仞。",
  ["$YS__dixing2"] = "靡坚不摧。",
  ["$YS__dixing3"] = "震天撼地。",
  ["$YS__dixing4"] = "安如磐石。",
  ["$YS__dixing5"] = "固若金汤。",
  ["$YS__dixing6"] = "俱收并蓄。",
  ["$YS__zhuanyv1"] = "遗珠弃璧，吉光片裘…",
  ["$YS__zhuanyv2"] = "也好。",
  ["$YS__dangmo1"] = "你的实力我姑且认可。",
  ["$YS__dangmo2"] = "力量似乎渐渐回来了。不多，但有用。",
  ["$YS__A_tianxing1"] = "天动万象。",
  ["$YS__A_tianxing2"] = "天理长驱。",
  ["$YS__A_tianxing3"] = "此乃天道。",
  ["~YS__zl"] = "啊，略感疲惫…",
  ["$YS__zl_win_audio"] = "欲买桂花同载酒…只可惜故人，何日再见呢?",
}



local YS__ht= General(extension, "YS__ht", "Pyro", 4, 4, General.Female)
local YS__htwin = fk.CreateActiveSkill{ name = "YS__ht_win_audio" }
YS__htwin.package = extension
Fk:addSkill(YS__htwin)
local YS__dieyin = fk.CreateActiveSkill{
  name = "YS__dieyin",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Frequent,
  mute = true,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke("YS__dieyin", math.random(1,3))
    room:loseHp(player, 1, self.name)
    if player.dead then return end
    room:setPlayerMark(player, "@@YS__dieyin-turn", 1)
    player:drawCards(1 + player:getLostHp(), self.name)
  end,
}
local YS__dieyin_filter = fk.CreateFilterSkill{
  name = "#YS__dieyin_filter",
  mute = true,
  card_filter = function(self, to_select, player)
    if player:hasSkill("YS__dieyin") and player.phase == Player.Play and
    table.contains(player.player_cards[Player.Hand], to_select.id) then
      if player:getMark("@@YS__dieyin-turn") == 1 then
        return to_select.trueName == "slash"
      end
    end
  end,
  view_as = function(self, to_select, player)
    local card
    if player:getMark("@@YS__dieyin-turn") == 1 then
      card = Fk:cloneCard("fire__slash", to_select.suit, to_select.number)
    end
    card.skillName = "YS__dieyin"
    return card
  end,
}
local YS__dieyinSlash = fk.CreateTriggerSkill{
  name = "#YS__dieyinSlash",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  mute = true,
  can_trigger = function(self, event, target, player, data)
      if target == player and player:hasSkill(YS__dieyin) and data.card.trueName == "slash" and player:getMark("@@YS__dieyin-turn") ~= 0 then
          local cardnum = player:getHandcardNum()
          return cardnum%2 == 1
      else
          return false
      end
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    if player:getMark("@@YS__dieyin-turn") ~= 0 then
      player:broadcastSkillInvoke("YS__dieyin", math.random(4,6))
      if to:getMark("@@xuemei") == 0 then
        player.room:setPlayerMark(to, "@@xuemei", 1)
      else
        if player.hp <= math.floor(player.maxHp / 2) then
        data.additionalDamage = (data.additionalDamage or 0) + 1
        end
      end
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target ~= player and target:getMark("@@xuemei") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    player.room:setPlayerMark(target, "@@xuemei", 0)
    room:damage{
      from = player,
      to = target,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = self.name,
    }
  end,
}
local YS__dieyinslash_buff = fk.CreateTargetModSkill{
  name = "#YS__dieyinslash_buff",
  mute = true,
  residue_func = function(self, player, skill, scope, card)
    local cardnum = player:getHandcardNum()
    return (player:getMark("@@YS__dieyin-turn") ~= 0 and skill.trueName == "slash_skill" and cardnum%2 == 0 and card.name == "fire__slash") and 998 or 0
  end,
}
local YS__anshenDamage = fk.CreateTriggerSkill{
  name = "#YS__anshenDamage",
  events = {fk.Damage, fk.Deathed},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damage then
      return target == player and player:usedSkillTimes("YS__anshen", Player.HistoryGame) == 0 and player:hasSkill(self.name)
    elseif event == fk.Deathed then
      return player:hasSkill(self) and data.damage and data.damage.from == player and target ~= player
    end
  end,
  on_cost = function(self, event, target, player, data)
      return true
    end,
  on_use = function(self, event, target, player, data)
    if event == fk.Damage then
    player.room:addPlayerMark(player, "@YS__anshenDamage", data.damage)
    elseif event == fk.Deathed then
    player:setSkillUseHistory("YS__anshen", 0, Player.HistoryGame)
    end
  end,
}

local YS__anshen = fk.CreateTriggerSkill{
  name = "YS__anshen",
  frequency = Skill.Limited,
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
      and player.phase == Player.Finish and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = player:getMark("@YS__anshenDamage")
    player:drawCards(num, self.name)
    room:recover({
      who = player,
      num = num,
      recoverBy = player,
      skillName = self.name
    })
    player.room:setPlayerMark(player, "@YS__anshenDamage", 0)
  end,
}
YS__ht:addSkill(YS__dieyin)
YS__dieyin:addRelatedSkill(YS__dieyin_filter)
YS__dieyin:addRelatedSkill(YS__dieyinSlash)
YS__dieyin:addRelatedSkill(YS__dieyinslash_buff)
YS__ht:addSkill(YS__anshen)
YS__anshen:addRelatedSkill(YS__anshenDamage)
Fk:loadTranslationTable{
  ["YS__ht"] = "胡桃",
  ["YS__dieyin"] = "蝶引",
  ["#YS__dieyin_filter"] = "蝶引",
  ["YS__anshen"] = "安神",
  ["#YS__anshenDamage"] = "安神",
  ["@YS__anshenDamage"] = "<font color='#CE0000'>安神</font>",
  ["@@xuemei"] = "<font color='Red'>血梅</font>",
  ["@@YS__dieyin-turn"] = "<font color='#EA0000'>蝶引</font>",
  ["#YS__dieyinSlash"] = "蝶引",
  [":YS__dieyin"] = "出牌阶段限一次，你可以失去一点体力并摸1+X张牌，然后本回合你的【杀】均视为火杀。<br/>" ..
  "/ / 当你的手牌数为偶数时，你使用【杀】无次数限制；<br/>/ / 当你的手牌数为奇数时，你使用【杀】指定目标后，若其没有“血梅”则你令其获得“血梅”，若其有“血梅”且你的体力值不大于上限的一半则此【杀】伤害+1。（X为你已损失体力值）"..
  "<br/><font color='red'>#\"<b>血梅</b>\"：该角色回合结束时，你移除并对其造成一点火焰伤害。",
  [":YS__anshen"] = "限定技，结束阶段，你可以回复Y点体力并摸Y张牌；当你杀死一名角色后重置此技能。（Y为你本局游戏造成伤害数）。",
  ["$YS__dieyin1"] = "喝！",
  ["$YS__dieyin2"] = "起！",
  ["$YS__dieyin3"] = "散！",
  ["$YS__dieyin4"] = "吃饱喝饱，一路走好！",
  ["$YS__dieyin5"] = "再会啦！",
  ["$YS__dieyin6"] = "蝶火燎原！",
  ["$YS__anshen1"] = "嗯，真舒服。",
  ["$YS__anshen2"] = "♪啦啦啦啦~吃水煮鱼配虾饺啦~",
  ["$YS__anshen3"] = "哦呀?哦呀呀?",
  ["~YS__ht"] = "干嘛呀！",
  ["$YS__ht_win_audio"] = "一波送走，全送走。",
}


local YS__ddly = General(extension, "YS__ddly", "Hydro", 4, 4, General.Male)
local YS__ddlywin = fk.CreateActiveSkill{ name = "YS__ddly_win_audio" }
YS__ddlywin.package = extension
Fk:addSkill(YS__ddlywin)
local YS__kuanglan = fk.CreateTriggerSkill{
  name = "YS__kuanglan",
  anim_type = "switch",
  switch_skill_name = "YS__kuanglan",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
      local room = player.room
      if player:getSwitchSkillState(self.name) == fk.SwitchYang then
      local dat = U.askForUseVirtualCard(room, player, "YS__water__slash", nil, self.name, "是否使用一张水杀，切换至远程", true, true, true, true, nil, true)
      if dat then
        self.cost_data = dat
        return true
      end
      else
        return room:askForSkillInvoke(player, self.name, nil, "是否切换至近战")
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(self.name) == fk.SwitchYin then
      room:setPlayerMark(player, "@@YS__kuanglan-Ranged Stance", 1)
      room:setPlayerMark(player, "@@YS__kuanglan-Melee Stance", 0)
      player.room:setPlayerMark(player, "range", 0)
      local use = self.cost_data
      room:useCard(use)
      player:broadcastSkillInvoke("YS__kuanglan", math.random(4,7))
    elseif player:getSwitchSkillState(self.name) == fk.SwitchYang then
    local r = player:getAttackRange()
    player:broadcastSkillInvoke("YS__kuanglan", math.random(1,3))
    room:setPlayerMark(player, "range", player:getMark("range") - r + 1)
    room:setPlayerMark(player, "@@YS__kuanglan-Melee Stance", 1)
    room:setPlayerMark(player, "@@YS__kuanglan-Ranged Stance", 0)
    local targets = table.map(table.filter(room.alive_players, function(p) return player:distanceTo(p) == 1 end), Util.IdMapper)
      for _, targetId in ipairs(targets) do
        room:getPlayerById(targetId):setChainState(true)
      end
    end
  end,

  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    local to = data.to
    return target == player and player:hasSkill(self) and player.phase == Player.Play and
      not to.dead
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local to = data.to
    if data.card.trueName == "slash" then
      if to:getMark("@@duanliu") ~= 0 and to ~= player and player:getMark("@@YS__kuanglan-Melee Stance") ~= 0 and not to:isNude() then
        room:doIndicate(player.id, {data.to.id})
        local card = room:askForCardChosen(player, to, "he", self.name)
        if card then
          room:obtainCard(player.id, card, false, fk.ReasonPrey)
        end
      end
    end
  end,
}
local YS__ningshui = fk.CreateTriggerSkill{
  name = "YS__ningshui",
  anim_type = "offensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
      if target == player and player:hasSkill(self) then
          local aims=#AimGroup:getAllTargets(data.tos)
          return aims==1 and data.card.trueName == "slash"
      else
          return false
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    local to = player.room:getPlayerById(targets[1])
    if to:getMark("@@duanliu") == 0 and (player:getMark("@@YS__kuanglan-Ranged Stance") ~= 0 or player:getMark("@@YS__kuanglan-Melee Stance") ~= 0 )then
      room:addPlayerMark(to, "@@duanliu", 1)
      if not to.chained then
      room:getPlayerById(targets[1]):setChainState(true)
      room:setPlayerMark(room:getPlayerById(targets[1]), "chain", 1)
      end
    elseif to:getMark("@@duanliu") ~= 0 and player:getMark("@@YS__kuanglan-Ranged Stance") ~= 0 then
      player:broadcastSkillInvoke("YS__ningshui", math.random(1,2))
      data.disresponsive = true
    end
  end,
}
local YS__ningshui_delay = fk.CreateTriggerSkill{
  name = "#YS__ningshui_delay",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local to = data.to
    if to:getMark("@@duanliu") ~= 0 then
    data.damageType = 328
    end
  end,

  refresh_events = {fk.EnterDying},
  can_refresh = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and player.phase == Player.Play and target:getMark("@@duanliu") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
  local room = player.room
    player.room:setPlayerMark(target, "@@duanliu", 0)
    target:setChainState(false)
    room:setPlayerMark(target, "chain", 0)
    player:broadcastSkillInvoke("YS__ningshui", math.random(3, 4))
    player:drawCards(1)
  end,

}
local duanliu = fk.CreateTriggerSkill{
  name = "#duanliu",
  mute = true,
  events = {fk.BeforeChainStateChange, fk.TurnStart,},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.BeforeChainStateChange then
      return target:getMark("@@duanliu") ~= 0 and target.chained and player.phase == Player.Play
    elseif event == fk.TurnStart then
      return target == player
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.BeforeChainStateChange then
      return true
    else
      local room = player.room
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return p ~= player and not p.chained and p:getMark("@@duanliu") ~= 0
      end), function(p)
        return p.id
      end)
      if #availableTargets == 0 then return false end
      for _, targetId in ipairs(availableTargets) do
        room:getPlayerById(targetId):setChainState(true)
        room:setPlayerMark(room:getPlayerById(targetId), "chain", 1)
      end
    end
  end,
}
local YS__kuanglan_targetmod = fk.CreateTargetModSkill{
  name = "#YS__kuanglan_targetmod",
  mute = true,
  bypass_distances =  function(self, player, skill, card, to)
    return (player:getMark("@@YS__kuanglan-Ranged Stance") ~= 0 and skill.trueName == "slash_skill")
  end,
  residue_func = function(self, player, skill, scope, card)
    return (player:getMark("@@YS__kuanglan-Melee Stance") ~= 0 and skill.trueName == "slash_skill") and 998 or 0
  end,
}
local YS__kuanglan_attackrange = fk.CreateAttackRangeSkill{
  name = "#YS__kuanglan_attackrange",
  mute = true,
  correct_func = function (self, from, to)
    return from:getMark("range")
  end,
}local rangePatch = fk.CreateTriggerSkill{
  name = "#rangePatch",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    local targets = TargetGroup:getRealTargets(data.tos)
    local to = player.room:getPlayerById(targets[1])
    return target == player and player:hasSkill(self.name) and to == player and player.phase == Player.Play and data.card.sub_type == Card.SubtypeWeapon
    and player:getMark("@@YS__kuanglan-Melee Stance") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "range", 0)
    local r = player:getAttackRange()
    room:setPlayerMark(player, "range", player:getMark("range") - r + 1)
  end,


  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.AfterCardsMove and player:getMark("@@YS__kuanglan-Melee Stance") ~= 0 then
      if player.phase == Player.NotActive then return false end
      for _, move in ipairs(data) do
        if move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerHand and move.toArea ~= Card.PlayerEquip)) then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon and (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
              return true
            end
          end
        end
      end
  end
end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "range", 0)
    local r = player:getAttackRange()
    room:setPlayerMark(player, "range", player:getMark("range") - r + 1)
  end,
}

local chainReset = fk.CreateTriggerSkill{
  name = "#chainReset",
  mute = true,
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p.chained and p:getMark("chain") ~= 0
    end), function(p)
      return p.id
    end)
    if #availableTargets == 0 then return false end
    for _, targetId in ipairs(availableTargets) do
      room:getPlayerById(targetId):setChainState(false)
      room:setPlayerMark(room:getPlayerById(targetId), "chain", 0)
    end
  end,
  priority = 2,
}
local YS__A_jinmie = fk.CreateTriggerSkill{
  name = "YS__A_jinmie",
  mute = true,
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("@@duanliu") ~= 0
    end), function(p)
      return p.id
    end)
    if player:hasSkill(self) and #availableTargets > 2 then
    return target == player and room:askForSkillInvoke(player, self.name, nil, "是否发动尽灭")
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("@@duanliu") ~= 0
    end), function(p)
      return p.id
    end)
    if #availableTargets == 0 then return false end
    if #availableTargets > 2 then
      player:broadcastSkillInvoke("YS__A_jinmie", math.random(1,2))
    for _, targetId in ipairs(availableTargets) do
      room:setPlayerMark(room:getPlayerById(targetId), "@@duanliu", 0)
      room:damage{
        from = player,
        to = room:getPlayerById(targetId),
        damage = 1,
        damageType = 328,
        skillName = self.name,
      }
    end
  end
  end,
}
YS__ddly:addSkill(YS__kuanglan)
YS__kuanglan:addRelatedSkill(YS__kuanglan_targetmod)
YS__kuanglan:addRelatedSkill(YS__kuanglan_attackrange)
YS__ddly:addSkill(YS__ningshui)
YS__ningshui:addRelatedSkill(YS__ningshui_delay)
YS__ningshui:addRelatedSkill(chainReset)
YS__ningshui:addRelatedSkill(duanliu)
YS__kuanglan:addRelatedSkill(rangePatch)
YS__ddly:addSkill(YS__A_jinmie)
Fk:loadTranslationTable{
  ["YS__ddly"] = "达达利亚",
  ["YS__kuanglan"] = "狂澜",
  ["YS__ningshui"] = "凝水",
  ["@@YS__kuanglan-Melee Stance"] = "<font color='#0072E3'>狂澜-近战</font>",
  ["@@YS__kuanglan-Ranged Stance"] = "<font color='#0072E3'>狂澜-远程</font>",
  ["@@duanliu"] = "<font color='#7ABEEA'>断流</font>",
  ["YS__A_jinmie"] = "尽灭",
  [":YS__kuanglan"] = "转换技，出牌阶段开始时，阳：你可以视为使用一张无距离限制且不计入次数的水【杀】，然后你切换至远程状态；<br/>"..
  "<font color='grey'>(远程状态下，你使用【杀】无距离限制，有“断流”的角色无法响应你使用的【杀】)</font><br/>"..
  "阴：你可以切换至近战状态并横置所有你与其距离为1的其他角色<br/>"..
  "<font color='grey'>（近战状态下，你的攻击距离始终为1，你使用【杀】无次数限制；当你使用【杀】对“断流”角色造成伤害后"..
  "你获得其一张牌。）</font>",
  [":YS__ningshui"] = "锁定技，你的回合内，①所有“断流”角色始终视为横置状态，你对有“断流”的角色造成的所有伤害均视为水元素伤害。②当有其他角色进入濒死状态时，你摸一张牌并移除其“断流”。③你使用【杀】指定其他角色为目标时，令其获得“断流”。",
  [":YS__A_jinmie"] = "结束阶段，若场上有“断流”的角色数不小于3，则你可以移除所有“断流”，对这些角色各造成一点水元素伤害。",
  ["$YS__kuanglan1"] = "哈！",
  ["$YS__kuanglan2"] = "势如狂澜！",
  ["$YS__kuanglan3"] = "要上了！",
  ["$YS__kuanglan4"] = "呼————",
  ["$YS__kuanglan5"] = "接下来——",
  ["$YS__kuanglan6"] = "来吧！",
  ["$YS__kuanglan7"] = "兵贵神速。",
  ["$YS__ningshui1"] = "逃得掉吗！",
  ["$YS__ningshui2"] = "一箭止水！",
  ["$YS__ningshui3"] = "哈！有点意思。",
  ["$YS__ningshui4"] = "真让人摩拳擦掌！",
  ["$YS__A_jinmie1"] = "破绽，稍纵即逝！",
  ["$YS__A_jinmie2"] = "忍着点，这可是很痛的。",
  ["$YS__ddly_win_audio"] = "哈，强敌何在?",
  ["~YS__ddly"] = "还挺…有两下子…",
}




local YS__gy = General(extension, "YS__gy", "Cryo", 3, 3, General.Female)
local YS__gywin = fk.CreateActiveSkill{ name = "YS__gy_win_audio" }
YS__gywin.package = extension
Fk:addSkill(YS__gywin)
local YS__liutian = fk.CreateTriggerSkill{
  name = "YS__liutian",
  anim_type = "offensive",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player.phase == Player.Play and player:getMark("@YS__liutian") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local cids = player.room:askForCard(player, 1, 1, true, self.name, true, "slash|.|.|hand,binglian|.|.|.", "将一张杀用于施法", "binglian")
    if #cids > 0 then
      self.cost_data = cids[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:addToPile("YS__liutianSlash", self.cost_data, true, self.name)
    local num = player.room:askForChoice(player, {"1", "2", "3","4","5"}, self.name, "流天：施法，第X个回合结束前，使用一张霜华。")
    player.room:setPlayerMark(player, "@YS__liutian", num .. "-" .. num)
  end,
}
local YS__liutian_conjure = fk.CreateTriggerSkill{
  name = "#YS__liutian_conjure",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@YS__liutian") ~= 0 and string.sub(player:getMark("@YS__liutian"), -1) == "0"
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local nums = string.split(player:getMark("@YS__liutian"), "-")
    local num = tonumber(nums[1])
    if #player:getPile("YS__liutianSlash") > 0 and target ~= player then
      room:notifySkillInvoked(player, "YS__liutian")
      player:broadcastSkillInvoke("YS__liutian", math.random(1,4))
      room:setPlayerMark(target, "YS__liutianSlash-turn", 1)
      local use = {
        from = player.id,
        tos = {{target.id}},
        card = Fk:getCardById(player:getPile("YS__liutianSlash")[1]),
        extraUse = true,
      }
      use.card.skillName = self.name
      room:useCard(use)
    else
      room:moveCards({
        from = player.id,
        ids = player:getCardIds(Player.Special,"YS__liutianSlash"),
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
        specialName = "YS__liutianSlash",
      })
    end
    room:setPlayerMark(player, "@YS__liutian", 0)
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@YS__liutian") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local nums = string.split(player:getMark("@YS__liutian"), "-")
    local num = tonumber(nums[1])
    local num2 = tonumber(nums[2]) - 1
    room:setPlayerMark(player, "@YS__liutian", num .. "-" .. num2)
  end,
}
local YS__liutianSlash = fk.CreateTriggerSkill{
  name = "#YS__liutianSlash",
  anim_type = "offensive",
  mute = true,
  events = {fk.PreCardEffect},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "#YS__liutian_conjure")
  end,
  on_use = function(self, event, target, player, data)
    local nums = string.split(player:getMark("@YS__liutian"), "-")
    local num = tonumber(nums[1])
    data.extra_data = data.extra_data or {}
    data.extra_data.YS__liutian = num
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    data.fixedResponseTimes["jink"] = data.extra_data.YS__liutian
    end,
}
local YS__liutianSlash2 = fk.CreateTriggerSkill{
  name = "#YS__liutianSlash2",
  anim_type = "offensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.to ~= player and data.to:getMark("YS__liutianSlash-turn") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    for _, id in ipairs(data.to:getCardIds("h")) do
      if Fk:getCardById(id).trueName == "jink" then
        n = n + 1
      end
    end
    if n > 0 then
      data.damage = data.damage + 1
    end
    if #room.draw_pile > 0 then
      local cards2 = room:getCardsFromPileByRule("slash|.|.|.|.|.|.", 1)
      if #cards2 > 0 then
      room:obtainCard(player, cards2[1], false, fk.ReasonJustMove)
      end
    end
  end,
}
local YS__linji = fk.CreateTriggerSkill{
  name = "YS__linji",
  anim_type = "defence",
  mute = true,
  events = {fk.PreCardUse, fk.PreCardRespond},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.NotActive and #player:getPile("binglian") < 3
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__linji", math.random(1,3))
    local room = player.room
    local cids = room:getNCards(1)
    player:addToPile("binglian", cids, true, self.name)
    if player.shield == 0 then
      room:changeShield(player, 1)
    end
  end,
}
local YS__linjiTrigger = fk.CreateTriggerSkill{
  name = "#YS__linjiTrigger",
  mute = true,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("binglian") > 2 and target ~= player and player:getMark("@YS__liutian") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local cids = player.room:askForCard(player, 1, 1, true, "YS__liutian", true, "slash|.|.|hand,binglian|.|.|.", "#YS__liutian_invoke::"..target.id, "binglian")
    if #cids > 0 then
      self.cost_data = cids[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("YS__liutianSlash", self.cost_data, true, "YS__liutian")
    local num = player.room:askForChoice(player, {"1", "2", "3","4","5"}, "YS__liutian", "流天：施法，第X个回合结束前，使用一张霜华。")
    player.room:setPlayerMark(player, "@YS__liutian", num .. "-" .. num)
    player.room:moveCardTo(player:getCardIds(Player.Special,"binglian"), Card.PlayerHand, player, fk.ReasonGive, self.name, "binglian", true, player.id)
  end,

  refresh_events = {fk.AfterCardTargetDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "#YS__liutian_conjure")
  end,
  on_refresh = function(self, event, target, player, data)
    local nums = string.split(player:getMark("@YS__liutian"), "-")
    local num = tonumber(nums[1])
    if num > 2 and #U.getUseExtraTargets(player.room, data) > 0 then
      local to = player.room:askForChoosePlayers(player, U.getUseExtraTargets(player.room, data, true),
      1, 1, "为此杀指定一个额外目标", "YS__liutian", true)
      player.room:setPlayerMark(player.room:getPlayerById(to[1]), "YS__liutianSlash-turn", 1)
      if #to > 0 then
        local targets = table.simpleClone(to)
        TargetGroup:pushTargets(data.tos, targets)
      end
    end
end,
}
local bingllian_distance = fk.CreateDistanceSkill{
  name = "#binglian_distance",
  correct_func = function(self, from, to)
    if to:hasSkill(YS__linji) and #to:getPile("binglian") ~= 0 and to.shield ~= 0 then
      return 1
    end
  end,
}
YS__gy:addSkill(YS__liutian)
YS__liutian:addRelatedSkill(YS__liutian_conjure)
YS__liutian:addRelatedSkill(YS__liutianSlash)
YS__liutian:addRelatedSkill(YS__liutianSlash2)
YS__gy:addSkill(YS__linji)
YS__linji:addRelatedSkill(YS__linjiTrigger)
YS__linji:addRelatedSkill(bingllian_distance)
Fk:loadTranslationTable{
  ["YS__gy"] = "甘雨",
  ["YS__liutian"] = "流天",
  ["#YS__liutian_invoke"] = "流天:将一张杀用于施法,从%dest的回合开始计时。",
  ["@YS__liutian"] = "流天",
  ["YS__linji"] = "麟迹",
  ["YS__liutianSlash"] = "霜华",
  ["binglian"] = "<font color='#95CACA'>冰莲</font>",
  [":YS__liutian"] = "出牌阶段开始时，若你没有“霜华”，则你可以将一张【杀】置于武将牌上称为“霜华”然后施法X：对当前回合角色使用一张无距离限制的“霜华”（为你自己则施法失败），此【杀】需要X张【闪】才能抵消，此【杀】造成伤害时你从牌堆中获得随机一张【杀】，若目标手牌中有【闪】，则造成的伤害+1。若X大于2，则此【杀】可以额外选择一名目标（X至少为1且至多为5）。<br/><font color='grey'>#\"<b>施法</b>\"<br/>一名角色的回合结束前，施法标记-1，减至0时执行施法效果。施法期间不能重复施法同一技能。",
  [":YS__linji"] = "你的回合外，当你使用或打出牌时，若你的“冰莲”小于3，则你可以将牌堆顶一张牌置于武将牌上称为“冰莲”，若你没有护甲则你获得一点护甲。若你有护甲且武将牌上有“冰莲”，则其他角色计算与你的距离+1。"..
  "其他角色的准备阶段开始时，若你的“冰莲”为3，则你可以获得所有“冰莲”然后发动一次〖流天〗。你可以用“冰莲”里的牌发动〖流天〗。",
  ["$YS__liutian1"] = "风雪的缩影。",
  ["$YS__liutian2"] = "如琉璃般飘落。",
  ["$YS__liutian3"] = "下一项工作是…",
  ["$YS__liutian4"] = "这项工作，该划掉了。",
  ["$YS__linji1"] = "霜寒化生。",
  ["$YS__linji2"] = "闲人勿扰。",
  ["$YS__linji3"] = "禁止接触。",
  ["$YS__gy_win_audio"] = "为了岩王帝君！",
  ["~YS__gy"] = "「契约」…尚未完成…",
}

local YS__xiao = General(extension, "YS__xiao", "Anemo", 4, 4, General.Male)
local YS__xiaowin = fk.CreateActiveSkill{ name = "YS__xiao_win_audio" }
YS__xiaowin.package = extension
Fk:addSkill(YS__xiaowin)
local YS__fenglun_record = fk.CreateTriggerSkill{
  name = "#YS__fenglun_record",
  anim_type = "offensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if (event == fk.CardUsing or event == fk.EventPhaseEnd) and target == player and player.phase == Player.Play then
      return player:getMark("YS__fenglun-turn") ~= 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      if player:getMark("YS__fenglun-turn") ~= 0 then
        local x = data.card.number
        if x > 0 then
            room:addPlayerMark(player, "@YS__fenglun_times-turn", -1)
          if player:getMark("@YS__fenglun_point-turn") < x then
            room:setPlayerMark(player, "@YS__fenglun_point-turn", x)
          else
            room:setPlayerMark(player, "YS__fenglun-turn", 0)
            room:setPlayerMark(player, "@YS__fenglun-turn", "YS__fenglun_failure")
          end
        else
          room:addPlayerMark(player, "@YS__fenglun_times-turn", -1)
          room:setPlayerMark(player, "YS__fenglun-turn", 0)
          room:setPlayerMark(player, "@YS__fenglun-turn", "YS__fenglun_failure")
        end
      end
      if (type(player:getMark("@fengunSuit-turn")) == "table" and #player:getMark("@fengunSuit-turn") ~= 4) and (player:getMark("ty-turn") == 0) then
        player:drawCards(1)
      end
    end
  end,
  priority = 2,
}
local YS__fenglun = fk.CreateTriggerSkill{
  name = "YS__fenglun",
  mute = true,
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.EventPhaseStart and player.phase == Player.Play and player:hasSkill(self) then
        local s = player.room:askForSkillInvoke(player, self.name, nil, "是否发动风轮！")
        if s then
          return player:hasSkill(self)
        else
          local room = player.room
          room:setPlayerMark(player, "@YS__fenglun_times-turn", 0)
          room:setPlayerMark(player, "@YS__fenglun_point-turn", 0)
          room:setPlayerMark(player, "YS__fenglun-turn", 0)
          room:setPlayerMark(player, "@YS__fenglun-turn", 0)
          room:setPlayerMark(player, "@fengunSuit-turn", 0)
          room:setPlayerMark(player, "@fengunType-turn", 0)
          room:setPlayerMark(player, "ty-turn", 0)
          local availableTargets = table.map(table.filter(room.alive_players, function(p) 
            return p ~= player and p:getMark("@@xiangmo-turn") ~= 0
          end), function(p)
            return p.id
          end)
          for _, targetId in ipairs(availableTargets) do
          player.room:setPlayerMark(room:getPlayerById(targetId), "@@xiangmo-turn", 0)
          end
          return false
        end
      else
        if player.phase == Player.Play then
        return player.phase == Player.Play and not player.dead and
        player:usedSkillTimes(self.name, Player.HistoryTurn) ~= 0 and
        player:getMark("YS__fenglun-turn") ~= 0 and ((type(player:getMark("@fengunSuit-turn")) == "table" and #player:getMark("@fengunSuit-turn") == 4) or (player:getMark("ty-turn") ~= 0) )
        end
    end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local room = player.room
      local availableTargets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p.dead
      end), Util.IdMapper)
      if #availableTargets == 0 then return false end
      local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "指定一名其他角色发动风轮", self.name, false)
      if #targets > 0 then
        player.room:doIndicate(player.id, targets)
        self.cost_data = targets[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data)
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke("YS__fenglun", math.random(1, 3))
      player.room:setPlayerMark(player, "YS__fenglun-turn", 1)
      player.room:setPlayerMark(player, "@YS__fenglun_times-turn", 2)
      player.room:setPlayerMark(to, "@@xiangmo-turn", 1)
    else
      local room = player.room
      if player.hp > 2 then
        player:broadcastSkillInvoke("YS__nuowu", math.random(4, 5))
      else
        player:broadcastSkillInvoke("YS__fenglun", 4)
      end
      player.room:setPlayerMark(player, "@YS__fenglun_times-turn", 2)
      room:setPlayerMark(player, "@YS__fenglun_point-turn", 0)
      player.room:setPlayerMark(to, "@@xiangmo-turn", 0)
      player:gainAnExtraPhase(Player.Play)
      player.room:setPlayerMark(player, "@fengunSuit-turn", 0)
      player.room:setPlayerMark(player, "@fengunType-turn", 0)
      player.room:setPlayerMark(player, "ty-turn", 0)
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name, true) and player.phase ~= Player.NotActive and data.card.suit ~= Card.NoSuit and player:getMark("YS__fenglun-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local suitsRecorded = type(player:getMark("@fengunSuit-turn")) == "table" and player:getMark("@fengunSuit-turn") or {}
    table.insertIfNeed(suitsRecorded, data.card:getSuitString(true))
    player.room:setPlayerMark(player, "@fengunSuit-turn", suitsRecorded)
    local typesRecorded = type(player:getMark("@fengunType-turn")) == "table" and player:getMark("@fengunType-turn") or {}
    local xax = data.card
    if(xax:getTypeString() == "basic")then
      table.insertIfNeed(typesRecorded, xax:getTypeString() .. "_char")
    end
    if(xax:getTypeString() == "trick")then
      table.insertIfNeed(typesRecorded, xax:getTypeString() .. "_char")
    end
    if(xax:getTypeString() == "equip")then
      table.insertIfNeed(typesRecorded, xax:getTypeString() .. "_char")
    end
    player.room:setPlayerMark(player, "@fengunType-turn", typesRecorded)
    if (typesRecorded[1]~=nil and typesRecorded[2]~=nil and typesRecorded[3]~=nil)then
      player.room:setPlayerMark(player, "ty-turn", 1)
    end
  end,
}
local YS__nuowu = fk.CreateActiveSkill{
  name = "YS__nuowu",
  mute = true,
  anim_type = "support",
  card_num = 0,
  target_num = 0,
  can_use = function (self, player, card)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function() return false end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke("YS__nuowu", math.random(1, 3))
    room:loseHp(player, 1, self.name)
    player:turnOver()
    if player:usedSkillTimes("YS__fenglun",Player.HistoryPhase) ~= 0 then
    player.room:setPlayerMark(player, "@YS__fenglun_times-turn", 3)
    room:setPlayerMark(player, "@YS__fenglun_point-turn", 0)
    room:setPlayerMark(player, "YS__fenglun-turn", 1)
    room:setPlayerMark(player, "@YS__fenglun-turn", 0)
    end
  end,
}
local YS__nuowuSlash = fk.CreateTriggerSkill{
  name = "#YS__nuowuSlash",
  mute = true,
  anim_type = "offensive",
  events = {fk.TurnedOver},
  can_trigger = function(self, event, target, player, data)
    if player.phase == Player.Play then
      return target == player and player:hasSkill(YS__nuowu) and not player:prohibitUse(Fk:cloneCard("slash"))
    else
      return target == player and player:hasSkill(YS__nuowu)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard "slash"
    local max_num = slash.skill:getMaxTargetNum(player, slash)
    local targets = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not player:isProhibited(p, slash) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 or max_num == 0 then return end
    local tos = room:askForChoosePlayers(player, targets, 1, max_num, "视为对一名其他角色使用杀", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard "YS__Anemo__slash"
    slash.skillName = self.name
    player:broadcastSkillInvoke("YS__nuowu", math.random(4, 5))
    room:useCard {
      from = target.id,
      tos = table.map(self.cost_data, function(pid) return { pid } end),
      card = slash,
      additionalDamage = 1,
      extraUse = true,
    }
  end,
}
local YS__fenglun_targetmod = fk.CreateTargetModSkill{
  name = "#YS__fenglun_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
      return to:getMark("@@xiangmo-turn") ~= 0 and player:getMark("YS__fenglun-turn") ~= 0 and player.phase ~= Player.NotActive
  end,
  bypass_distances = function(self, player, skill, card, to)
      return to:getMark("@@xiangmo-turn") ~= 0 and player:getMark("YS__fenglun-turn") ~= 0 and player.phase ~= Player.NotActive
  end,
}
local YS__fenglunP = fk.CreateProhibitSkill{
  name = '#YS__fenglun_prohibit',
  prohibit_use = function(self, player)
  if player:usedSkillTimes("YS__fenglun", Player.HistoryPhase) ~= 0 then
    return player:hasSkill(YS__fenglun) and player.phase == Player.Play and ((player:getMark("YS__fenglun-turn") == 0 and player:getMark("@YS__fenglun-turn") == "YS__fenglun_failure") or player:getMark("@YS__fenglun_times-turn") == 0)
  end
  end,
}
YS__xiao:addSkill(YS__fenglun)
YS__fenglun:addRelatedSkill(YS__fenglun_record)
YS__fenglun:addRelatedSkill(YS__fenglun_targetmod)
YS__fenglun:addRelatedSkill(YS__fenglunP)
YS__xiao:addSkill(YS__nuowu)
YS__nuowu:addRelatedSkill(YS__nuowuSlash)
Fk:loadTranslationTable{
  ["YS__xiao"] = "魈",
  ["YS__fenglun"] = "风轮",
  ["YS__nuowu"] = "傩舞",
  ["@YS__fenglun_point-turn"] = "<font color='#02C874'>擂进</font>",
  ["@@xiangmo-turn"] = "<font color='#006030'>降魔</font>",
  ["@YS__fenglun-turn"] = "风轮",
  ["YS__fenglun_failure"] = "中断",
  ["@fengunSuit-turn"] = "<font color='#01B468'>空劫</font>",
  ["@fengunType-turn"] = "<font color='#019858'>坏劫</font>",
  ["@YS__fenglun_times-turn"] = "<font color='#01814A'>业障</font>",
  [":YS__fenglun"] = "出牌阶段开始时，你可以指定一名其他角色并进入“风轮状态”，然后本阶段你只能使用2张牌，且你对该角色使用牌无次数和距离限制；<br/>当你使用的牌的点数不与本阶段你使用过的牌形成递增数列时，你中断“风轮状态”且无法再使用牌。"..
  "<br/>此出牌阶段结束时，若你使用了3种不同类别的牌或4种不同花色的牌且未中断“风轮状态”，则你可以执行一个额外的出牌阶段；<br/>本阶段你使用牌后，若未达成执行额外出牌阶段的条件，你摸一张牌。",
  [":YS__nuowu"] = "出牌阶段限一次，你可以失去一点体力并将武将牌翻面，然后你清除本阶段风轮点数的记录且将〖风轮〗可使用牌次数重置至3。当你翻面时，你可以视为使用一张无距离和次数限制且伤害+1的风【杀】。",
  ["$YS__fenglun1"] = "哼",
  ["$YS__fenglun2"] = "无聊。",
  ["$YS__fenglun3"] = "无用",
  ["$YS__fenglun4"] = "别妨碍我。",
  ["$YS__nuowu1"] = "悲鸣吧。",
  ["$YS__nuowu2"] = "靖妖傩舞。",
  ["$YS__nuowu3"] = "就此消失。",
  ["$YS__nuowu4"] = "无能。",
  ["$YS__nuowu5"] = "这里！",
  ["$YS__xiao_win_audio"] = "降魔乃分内之事。",
  ["~YS__xiao"] = "不可能…"
}





local YS__yf = General(extension, "YS__yf", "Pyro", 3, 3, General.Female)
local YS__yfwin = fk.CreateActiveSkill{ name = "YS__yf_win_audio" }
YS__yfwin.package = extension
Fk:addSkill(YS__yfwin)
local YS__danhuo = fk.CreateActiveSkill{
  name = "YS__danhuo",
  anim_type = "offensive",
  mute = true,
  card_num = 0,
  target_num = 1,
  prompt = "#YS__danhuo",
  can_use = function(self, player)
    return not player:isKongcheng() and player:getMark("@@YS__danhuostop-turn") == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      if not target.dead then
        player:broadcastSkillInvoke("YS__danhuo", math.random(1,3))
        room:damage{
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = self.name,
        }
        player:drawCards(1)
        target:drawCards(1)
      end
    else
      room:changeShield(player, 2)
      player:broadcastSkillInvoke("YS__danhuo", math.random(4,6))
      room:setPlayerMark(player,"@@YS__danhuostop-turn",1)
    end
  end,
}
local YS__danhuo_trigger = fk.CreateTriggerSkill{
  name = "#YS__danhuo_trigger",
  mute = true,
  events = {fk.EnterDying, fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    return data.damage and data.damage.skillName == "YS__danhuo" and data.damage.from and data.damage.from == player and not player.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if event == fk.EnterDying then
      data.extra_data = data.extra_data or {}
      data.extra_data.YS__danhuo = player.id
    elseif data.extra_data.YS__danhuo == player.id and not target.dead then
      local room = player.room
      player:broadcastSkillInvoke("YS__danhuo", 7)
      room:setPlayerMark(player, "@@YS__danhuostop-turn", 1)
      room:changeShield(player, 1)
    end
  end,
}
local YS__danhuo_attackrange = fk.CreateAttackRangeSkill{
  name = "#YS__danhuo_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("YS__danhuo") then
      return -1000
    end
    return 0
  end,
}
local YS__danhuo_prohibit = fk.CreateProhibitSkill{
  name = "#YS__danhuo_prohibit",
  prohibit_use = function(self, player, card)
    return card and card.trueName == "slash" and player:hasSkill("YS__danhuo")
  end,
}
local YS__danhuo_maxcards = fk.CreateMaxCardsSkill{
  name = "#YS__danhuo_maxcards",
  correct_func = function(self, player)
    return player:hasSkill(YS__danhuo) and player.shield or 0
  end,
}
local YS__zhuozhuo = fk.CreateActiveSkill{
  name = "YS__zhuozhuo",
  anim_type = "drawcard",
  min_card_num = 2,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return false
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local number = 0
    for _, id in ipairs(effect.cards) do
      number = number + math.max(Fk:getCardById(id).number, 0)
    end

    number = number % 13
    number = number == 0 and 13 or number

    room:throwCard(effect.cards, self.name, from, from)

    local randomId = room:getCardsFromPileByRule(".|" .. number)
    if #randomId > 0 then
      room:obtainCard(from, randomId[1], true, fk.ReasonPrey)
    end
    if from.shield ~= 0 then
      local s = room:askForSkillInvoke(from, self.name, nil, "是否失去一点护甲并摸一张牌令本技能视为未发动过。")
      if s then
        room:changeShield(from,-1)
        from:drawCards(1)
        from:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
      end
    end
  end,
}
YS__yf:addSkill(YS__danhuo)
YS__danhuo:addRelatedSkill(YS__danhuo_attackrange)
YS__danhuo:addRelatedSkill(YS__danhuo_maxcards)
YS__danhuo:addRelatedSkill(YS__danhuo_prohibit)
YS__danhuo:addRelatedSkill(YS__danhuo_trigger)
YS__yf:addSkill(YS__zhuozhuo)
Fk:loadTranslationTable{
  ["YS__yf"] = "烟绯",
  ["YS__danhuo"] = "丹火",
  [":YS__danhuo"] = "锁定技，①出牌阶段，你可以与一名角色拼点，若你赢则你对其造成一点火焰伤害，然后你与其各摸一张牌，且若其因此进入濒死状态且被救回，则濒死状态结算后你获得一点护甲且本回合不能再发动此技能；若你没赢，你获得两点护甲且本回合不能再发动此技能。②你无法使用【杀】且攻击范围始终为0，你的手牌上限+X（X为你的护甲值）。",
  ["@@YS__danhuostop-turn"] = "<font color='#FF5151'>丹火失效</font>",
  ["YS__zhuozhuo"] = "灼灼",
  [":YS__zhuozhuo"] = "出牌阶段限一次，你可以弃置至少两张牌，然后从牌堆中随机获得一张点数为X的牌（X为以此法弃置的牌点数和与13的余数，若余数为0则改为13），且若你有护甲，则你可以失去一点护甲并摸一张牌视为本回合未发动过此技能。",
  ["#YS__danhuo"] = "丹火：你可以与一名角色拼点，若你赢你对其造成一点火焰伤害；否则，你获得一点护甲且此技能失效直到回合结束。",
  ["$YS__danhuo1"] = "嘣嘣——",
  ["$YS__danhuo2"] = "焚烧吧！",
  ["$YS__danhuo3"] = "速速退下！",
  ["$YS__danhuo4"] = "得修正错误！",
  ["$YS__danhuo5"] = "你犯规…",
  ["$YS__danhuo6"] = "什么，有纰漏？",
  ["$YS__danhuo7"] = "放马过来。",
  ["$YS__zhuozhuo1"] = "律火，引！",
  ["$YS__zhuozhuo2"] = "食炎之罚！",
  ["$YS__zhuozhuo3"] = "丹书铁契！",
  ["~YS__yf"] = "判断…失误了吗…",
  ["$YS__yf_win_audio"] = "我现在应该算「文武双全」了吧！",
}

local YS__kq = General(extension, "YS__kq", "Electro", 3, 3, General.Female)
local YS__kqwin = fk.CreateActiveSkill{ name = "YS__kq_win_audio" }
YS__kqwin.package = extension
Fk:addSkill(YS__kqwin)
local YS__xingdou = fk.CreateActiveSkill{
  name = "YS__xingdou",
  anim_type = "control",
  prompt = "#YS__xingdou-active",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) <= 0 + player:getMark("YS__tianxun-turn")
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:notifySkillInvoked(player, self.name, "control")
    local XD = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
    room:setPlayerMark(room:getPlayerById(XD[1]), "@TXseat-turn", 0)
    room:setPlayerMark(to, "@TXseat-turn", 1)
    local TXstart = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
    local temp = room:getPlayerById(TXstart[1]).next
    local targets = {}
    while temp ~= room:getPlayerById(TXstart[1]) do
      if not temp:isRemoved() and not temp.dead then
        table.insert(targets, temp)
      end
      temp = temp.next
    end
    for i ,p in ipairs(targets) do
      if not p.dead then
        room:setPlayerMark(p,"@TXseat-turn", i + 1)
      end
    end
  end,
}
local YS__xingdou_targetmod = fk.CreateTargetModSkill{
  name = "#YS__xingdou_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
      local room = Fk:currentRoom()
      local num = card.number % #room.alive_players
      num = num == 0 and #room.alive_players or num
      return card and player:getMark("@TXseat-turn") ~= 0 and card.number > 0 and
      num == to:getMark("@TXseat-turn")
  end,
  bypass_distances = function(self, player, skill, card, to)
    local room = Fk:currentRoom()
    local num = card.number % #room.alive_players
    num = num == 0 and #room.alive_players or num
    return card and player:getMark("@TXseat-turn") ~= 0 and card.number > 0 and
    num == to:getMark("@TXseat-turn")
  end,
}
local YS__tianxun = fk.CreateActiveSkill{
  name = "YS__tianxun",
  anim_type = "drawcard",
  min_card_num = 1,
  card_filter = function(self, to_select, selected)
    local room = Fk:currentRoom()
    return not Self:prohibitDiscard(Fk:getCardById(to_select)) and #selected <= 0 + math.min(Self:usedSkillTimes(self.name, Player.HistoryPhase), 2)
  end,
  target_num = 0,
  can_use = function(self, player)
    return player:getMark("@YS__tianxun") == 0
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:notifySkillInvoked(from, self.name)
    room:setPlayerMark(from, "@YS__tianxun", 1 + from:usedSkillTimes(self.name, Player.HistoryPhase))
    for _, id in ipairs(effect.cards) do
      local num = Fk:getCardById(id).number
      local seat = 0
      seat = num % #room.alive_players
      seat = seat == 0 and #room.alive_players or seat
      local TXstart = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
      local temp = room:getPlayerById(TXstart[1]).next
      local targets = {}
      while temp ~= from do
        if not temp:isRemoved() and not temp.dead then
          table.insert(targets, temp)
        end
        temp = temp.next
      end
      for i ,p in ipairs(targets) do
        if not p.dead then
          room:setPlayerMark(p,"@TXseat-turn", i + 1)
        end
      end
      if table.find(room.alive_players, function(p) return p ~= from and p:getMark("@TXseat-turn") == seat and not p:isRemoved() end) then
      local ta = table.map(table.filter(room.alive_players, function(p) return p ~= from and p:getMark("@TXseat-turn") == seat end), function(p) return p.id end)
      room:damage{
        from = from,
        to = room:getPlayerById(ta[1]),
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
      else
        from:drawCards(2)
      end
    end
    room:throwCard(effect.cards, self.name, from, from)
    room:addPlayerMark(from, "YS__tianxun-turn", 1)
  end
}
local YS__tianxun_trigger = fk.CreateTriggerSkill{
  name = "#YS__tianxun_trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("YS__xingdou", math.random(1,3))
    room:notifySkillInvoked(player, "YS__xingdou")
    room:setPlayerMark(player, "@TXseat-turn", 1)
    local TXstart = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
    local temp = room:getPlayerById(TXstart[1]).next
    local targets = {}
    while temp ~= room:getPlayerById(TXstart[1]) do
      if not temp:isRemoved() and not temp.dead then
        table.insert(targets, temp)
      end
      temp = temp.next
    end
    for i ,p in ipairs(targets) do
      if not p.dead then
        room:setPlayerMark(p,"@TXseat-turn", i + 1)
      end
    end
    for _, id in ipairs(player:getCardIds("he")) do
      if Fk:getCardById(id).number ~= nil then
        local num = Fk:getCardById(id).number
        local seat = 0
        seat = num % #room.alive_players
        seat = seat == 0 and #room.alive_players or seat
        room:setCardMark(Fk:getCardById(id), "@XDBJ-turn", seat)
      end
    end
  end,

  refresh_events = {fk.Death},
  can_refresh = function(self, event, target, player, data)
    return target:getMark("@TXseat-turn") ~= 0 and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local B = table.map(table.filter(room.alive_players, function(p) return p:hasSkill(self) end), function(p) return p.id end)
    for _, id in ipairs(room:getPlayerById(B[1]):getCardIds("he")) do
      if Fk:getCardById(id).number ~= nil then
        local num = Fk:getCardById(id).number
        local seat = 0
        seat = num % #room.alive_players
        seat = seat == 0 and #room.alive_players or seat
        room:setCardMark(Fk:getCardById(id), "@XDBJ-turn", seat)
      end
    end
    if target:getMark("@TXseat-turn") == 1 then
    local to = target.next
    while to:isRemoved() or to.dead do
      to = to.next
    end
    room:setPlayerMark(to, "@TXseat-turn", 1)
    local TXstart = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
    local temp = room:getPlayerById(TXstart[1]).next
    local targets = {}
    while temp ~= room:getPlayerById(TXstart[1]) do
      if not temp:isRemoved() and not temp.dead then
        table.insert(targets, temp)
      end
      temp = temp.next
    end
    for i ,p in ipairs(targets) do
      if not p.dead then
        room:setPlayerMark(p,"@TXseat-turn", i + 1)
      end
    end
    else
    local TXstart = table.map(table.filter(room.alive_players, function(p) return p:getMark("@TXseat-turn") == 1 end), function(p) return p.id end)
    local temp = room:getPlayerById(TXstart[1]).next
    local targets = {}
    while temp ~= room:getPlayerById(TXstart[1]) do
      if not temp:isRemoved() and not temp.dead then
        table.insert(targets, temp)
      end
      temp = temp.next
    end
    for i ,p in ipairs(targets) do
      if not p.dead then
        room:setPlayerMark(p,"@TXseat-turn", i + 1)
      end
    end
    end
  end,
}
local YS__xingdou_trigger = fk.CreateTriggerSkill{
  name = "#YS__xingdou_trigger",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.PreCardUse, fk.PreCardRespond},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("@YS__tianxun") ~= 0
  end,
  on_use = function(self, event, player, target, data)
    player.room:addPlayerMark(player, "@YS__tianxun", -1)
  end,


  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return player:hasSkill(self.name, true) and player.phase ~= Player.NotActive
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand then
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player then
              local num = Fk:getCardById(id).number
              local seat = 0
              seat = num % #room.alive_players
              seat = seat == 0 and #room.alive_players or seat
              room:setCardMark(Fk:getCardById(id), "@XDBJ-turn", seat)
            end
          end
        end
      end
    end
  end,
}

YS__kq:addSkill(YS__xingdou)
YS__xingdou:addRelatedSkill(YS__xingdou_targetmod)
YS__kq:addSkill(YS__tianxun)
YS__tianxun:addRelatedSkill(YS__tianxun_trigger)
YS__tianxun:addRelatedSkill(YS__xingdou_trigger)
Fk:loadTranslationTable{
  ["YS__kq"] = "刻晴",
  ["YS__xingdou"] = "星斗",
  [":YS__xingdou"] = "你的回合，以你为始，以逆时针方向按自然数列依次令所有角色获得不同标号的“雷楔”，你对拥有“雷楔X”的角色使用牌无距离和次数限制。出牌阶段限一次，你可以指定一名角色然后改变“雷楔”的起始。（X为此牌点数与当前场上存活角色数的余数，若为0则改为当前场上存活角色数）",
  ["#YS__xingdou_trigger"] = "星斗",
  ["#YS__xingdou-active"] = "星斗：你可以选择一名角色改变星斗的起始",
  ["YS__tianxun"] = "天巡",
  [":YS__tianxun"] = "昂扬技，出牌阶段，你可以弃置至多X+1(上限为3)张牌，然后你对这些牌的点数对应的雷楔目标各造成一点雷电伤害，若为你则改为摸两张牌。然后你本回合可以额外使用一次〖星斗〗。<br/><u>激昂</u>：你使用或打出1+X张牌。(X为本回合你使用此技能的次数)"..
  "<br/><font color='grey'>#\"<b>昂扬技</b>\"：昂扬技发动后，技能失效直到满足<b>激昂</b>条件。",
  ["@TXseat-turn"] = "<font color='#BE77FF'>雷楔</font>",
  ["@XDBJ-turn"] = "雷楔",
  ["@YS__tianxun"] = "<font color='#8600FF'>星斗·归位</font>",
  ["$YS__xingdou1"] = "可别眨眼。",
  ["$YS__xingdou2"] = "去吧！",
  ["$YS__xingdou3"] = "迅影如剑！",
  ["$YS__tianxun1"] = "剑出，影随——",
  ["$YS__tianxun2"] = "剑光如我，斩尽芜杂！",
  ["$YS__tianxun3"] = "无处可逃！",
  ["$YS__kq_win_audio"] = "心有所向，日复一日，必有精进。",
  ["~YS__kq"] = "太不甘心了…",
}

local YS__ng = General(extension, "YS__ng", "Geo", 3, 3, General.Female)
local YS__ngwin = fk.CreateActiveSkill{ name = "YS__ng_win_audio" }
YS__ngwin.package = extension
Fk:addSkill(YS__ngwin)
local YS__qianjin_ori = fk.CreateViewAsSkill {
  name = "YS__qianjin_ori",
  pattern = "slash,jink",
  interaction = function()
    local names = {}
    for _, id in ipairs(Self:getCardIds(Player.Hand)) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeBasic and not card.is_derived and (card.trueName == "slash" or card.trueName == "jink") and
          ((Fk.currentResponsePattern == nil and card.skill:canUse(Self, card)) or
            (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox { choices = names }
  end,
  card_filter = function(self, to_select, selected)
    local card = Fk:getCardById(to_select)
    if Fk:currentRoom():getCardArea(to_select) ~= Player.Equip and card.type == Card.TypeBasic then
      if #selected == 0 then
        return true
      elseif card.trueName == Fk:getCardById(selected[1]).trueName then
        return true
      end
    end
  end,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local sum = 0
    local num = 0
    for _, id in ipairs(cards) do
      local cardname = Fk:getCardById(id).name
      if cardname == self.interaction.data then
        sum = sum + 1
      end
      num = num + 1
    end
    if sum == 0 then return end
    if num < 2 then return end

    if not table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end) then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local num = #use.card.subcards
    local room = player.room
    if num >= 2 then
      local c = Fk:cloneCard(self.interaction.data)
      if c.trueName == "slash" then
        use.additionalDamage = (use.additionalDamage or 0) + num - 1
      elseif c.trueName == "jink" then
        if room.current ~= player then
        local cards = room:askForCard(room.current, num, num, true, self.name, false, ".", "#qianjin-discard:::" .. tostring(num), nil, false)
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
        end
      end
    end
  end,
  after_use = function(self, player, use)
    local room = player.room
    local num = #use.card.subcards
    if not use.damageDealt and use.card.trueName == "slash" then
      player:drawCards(num)
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1 + player:getMark("resetxuanji-turn")
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1 + player:getMark("resetxuanji-turn")
  end,
}
local YS__xuanji = fk.CreateTriggerSkill{
  name = "YS__xuanji",
  events = {fk.EventPhaseStart, fk.EnterDying, fk.AskForPeaches},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player:hasSkill(self) and player.phase == Player.Play
    elseif event == fk.EnterDying and player:hasSkill(self) then
      if target ~= player then
        return target:getMark("@@xuanji") ~= 0 and target ~= player
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "YS__xuanji")
    player:broadcastSkillInvoke("YS__xuanji", math.random(1,2))
    if event == fk.EventPhaseStart then
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#YS__xuanji-choose", self.name, true, false)
    if #tos > 0 then
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
          return p:getMark("@@xuanji") ~= 0
        end), function(p)
          return p.id
        end)
      if #availableTargets > 0 then
        for _, targetId in ipairs(availableTargets) do
          room:setPlayerMark(room:getPlayerById(targetId), "@@xuanji", 0)
        end
      end
      local to = room:getPlayerById(tos[1])
      room:setPlayerMark(to, "@@xuanji", 1)
    end
    elseif event == fk.EnterDying then
      if target ~= player then
      local cards = {}
      for _, id in ipairs(target:getCardIds("h")) do
        if Fk:getCardById(id).type == Card.TypeBasic then
          table.insert(cards, id)
        end
      end
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      room:setPlayerMark(target, "@@xuanji", 0)
      room:setPlayerMark(player, "resetxuanji-turn", 1)
      room:addPlayerMark(player, MarkEnum.SlashResidue.."-phase")
      end
    end
  end,
}
local YS__tianquan = fk.CreateMaxCardsSkill{
  name = "YS__tianquan",
  exclude_from = function(self, player, card)
    return player:hasSkill(self) and card.type == Card.TypeBasic
  end,
}
YS__ng:addSkill(YS__qianjin_ori)
YS__ng:addSkill(YS__xuanji)
YS__ng:addSkill(YS__tianquan)


Fk:loadTranslationTable{
  ["YS__ng"] = "凝光",
  ["YS__qianjin_ori"] = "千金",
  ["#qianjin-discard"] = "千金:交出 %arg 张牌",
  [":YS__qianjin_ori"] = "每回合限一次，你可以将至少两张【杀】/【闪】当做其中一张使用或打出，" ..
  "你以此法使用的【杀】伤害+(X-1)。若此【杀】未造成伤害，你摸X张牌。若你以此法使用了【闪】，你令当前回合角色交给你X张牌（X为你以此法使用的牌）",
  ["YS__xuanji"] = "璇玑",
  [":YS__xuanji"] = "出牌阶段开始时，你可以令一名角色获得“璇玑屏”（场上至多存在一个）。有“璇玑屏”的角色进入濒死时，你可以移除其“璇玑屏”并获得其手牌中所有基本牌且本回合可以额外使用一次〖千金〗且出杀次数+1。",
  ["#YS__xuanji-choose"] = "璇玑：令一名角色获得璇玑屏",
  ["YS__tianquan"] = "天权",
  [":YS__tianquan"] = "锁定技，你的基本牌不计入手牌上限。",
  ["@@xuanji"] = "<font color='#EAC100'>璇玑屏</font>",
}

return extension